function getToken(){
		var accessKey = "OxbuNqmdgmYB6KXiT72CK7NzNLf-jlx3gNsfHrgs";
		var secretKey = "jzTZQc6EQhMJ7uzJ1FP_zH60Y4nzkcWJoS4V8h92";
		//deadline unix的时间戳   让token到2020年失效
	    var putPolicy = {"scope" : "nezer-files","deadline" : 1905064271};
		//SETP 2
		var put_policy = JSON.stringify(putPolicy);
		// console && console.log("put_policy = ", put_policy);
		//SETP 3
		var encoded = base64encode(utf16to8(put_policy));
		// console && console.log("encoded = ", encoded);
	    //SETP 4
	    var hash = CryptoJS.HmacSHA1(encoded, secretKey);
		var encoded_signed = hash.toString(CryptoJS.enc.Base64);
		// console && console.log("encoded_signed=", encoded_signed);
		//SETP 5
		var upload_token = accessKey + ":" + safe64(encoded_signed) + ":" + encoded;
		return upload_token;
}

function uploadFileQN(file,finish,progress){
	uploadToQiniu(file,null,finish,progress)
}

function uploadPdfToQN(file,finish,progress){
	uploadToQiniu(file,['application/pdf'],finish,progress)
}

function uploadVideoToQN(file,finish,progress){
	uploadToQiniu(
		file,
		["video/mp4","video/ogg","video/x-flv","video/x-msvideo","video/x-ms-wmv","application/vnd.rn-realmedia-vbr"],
		finish,
		progress
	)
}

function uploadImageToQN(file,finish,progress){
	uploadToQiniu(file, ["image/png","image/jpeg","image/bmp"],finish,progress)
}

function uploadToQiniu(file,mime,finish,progress) {
		var time = new Date();
		var suffix = file.name.substr(file.name.lastIndexOf('.'));
		var key = time.getFullYear()+''+time.getMonth()+''+time.getDate()+''+time.getHours()+''+time.getMinutes()+''+time.getSeconds()+''+time.getMilliseconds() +'_video'+suffix;
		var observable = qiniu.upload(file,key, getToken(), {
				mimeType: mime?mime:''
		    }, {
				useCdnDomain: true,
				region: qiniu.region.z1
			}
		);
		var subscription = observable.subscribe(function(next){
			progress(next)
		}, function(err){
			console.log(err,'err')
		}, function(complate){
			finish(complate)
		})	
}

function deleteQiniuFile(fileName) {
	$.ajax({
		url:'/admin/video/file/delete',
		type:'get',
		data:{
			name:fileName
		},
		success:function (res) {
			console.log(res)
		}
	})
}